package clues.bihu.cluesaccident.jpush;

import android.app.Activity;
import android.widget.Toast;

import clues.bihu.cluesaccident.ClueBaseApp;
import clues.bihu.cluesaccident.JPushUtil;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.PluginRegistry;

public class ToastPlugin implements MethodChannel.MethodCallHandler {

    private Activity activity;
    private static final String CHANNEL_METHED = "plugins.flutter.io/toast_method";


    private ToastPlugin(Activity context) {
        activity = context;
    }

    public static void registerWith(PluginRegistry.Registrar registrar) {
        MethodChannel channel = new MethodChannel(registrar.messenger(), CHANNEL_METHED);
        ToastPlugin jpushPlugin = new ToastPlugin(registrar.activity());
        channel.setMethodCallHandler(jpushPlugin);
    }


    @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        try {
            String content = methodCall.argument("content");
            switch (methodCall.method) {
                case "toastLong": {
                    Toast.makeText(ClueBaseApp.Companion.getAppContext(), content, Toast.LENGTH_LONG).show();
                    break;
                }
                case "toastShort": {
                    Toast.makeText(ClueBaseApp.Companion.getAppContext(), content, Toast.LENGTH_SHORT).show();
                    break;
                }
            }

        } catch (Exception e) {
            result.error("IOException encountered", methodCall.method, e);
        }
    }


}
